package com.zlf.sb.demo;

import java.util.concurrent.LinkedBlockingDeque;

/***
 *@title RealTimeDataProcessing
 *@description <TODO description class purpose>
 *@author wgc_j
 *@version 1.0.0
 *@create 2025-02-25 18:04
 **/
public class RealTimeDataProcessing {
    private static final int NUM_OF_DATA = 1000;
    private static final LinkedBlockingDeque<String> dataQueue = new LinkedBlockingDeque<>();

    public static void main(String[] args) {
        Thread producer = new Thread(() -> {
            for (int i = 0; i < NUM_OF_DATA; i++) {
                try {
                    String data = "Data-" + i;
                    dataQueue.put(data);
                    System.out.println("Produced:" + data);
                } catch (InterruptedException e) {
                }
            }
        });
// 数据消费者线程
        Thread consumer = new Thread(() -> {
            while (true) {
                try {
                    String data = dataQueue.take();
                    System.out.println("Consumed:" + data);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    break;
                }
            }
        });
        producer.start();
        consumer.start();
        //consumer.start();
    }

}
